package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.threadlocal.UserThreadLocal;
import com.zzyl.nursing.dto.MemberElderDto;
import com.zzyl.nursing.dto.QueryDevicePropertyStatusDTO;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.vo.DeviceDataVO;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MemberElderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IFamilyMemberElderService iFamilyMemberElderService;

    @Autowired
    private IDeviceService iIDeviceService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }
    /**
     * 绑定家人
     *
     * @param memberElderDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "绑定家人")
    public AjaxResult add(@RequestBody MemberElderDto memberElderDto) {
        iFamilyMemberElderService.add(memberElderDto);
        return success();
    }

    /**
     * 查询家人
     *
     * @return 客户老人关联实体类
     */
    @GetMapping("/my")
    public R<List<FamilyMemberElderVo>> my() {
        List<FamilyMemberElderVo> memberElders = iFamilyMemberElderService.my();
        return R.ok(memberElders);
    }

    /**
     * 查看家人列表
     */
    @GetMapping("/list-by-page")
    public R<List<MemberElderVo>> listByPage(Integer pageNum, Integer pageSize) {
        startPage();
        Long userId = UserThreadLocal.getUserId();
        List<MemberElderVo> memberElders = iFamilyMemberElderService.listByPage(userId);
        return R.ok(memberElders);
    }

    /**
     * 查询健康数据
     */
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusDTO dto) {
        return iIDeviceService.queryDevicePropertyStatus(dto);
    }

    /**
     * 按天统计查询指标数据
     */
    /*
    使用了 @GetMapping 但又使用 @RequestBody：GET 请求通常不包含请求体，所以不能使用 @RequestBody 注解。
        参数传递方式不正确：GET 请求应该通过 URL 参数传递，而不是请求体。
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataByDay(
            @RequestParam("functionId") String functionId,
            @RequestParam("startTime") Long startTime,
            @RequestParam("endTime")Long endTime,
            @RequestParam("iotId")String iotId) {
        List<DeviceDataVO> list = iIDeviceService.queryDeviceDataByDay(functionId,startTime,endTime,iotId);
        return success(list);
    }

    /**
     * 按周统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周查询设备数据")
    public R<List<DeviceDataVO>> queryDeviceDataListByWeek(
            @RequestParam("functionId") String functionId,
            @RequestParam("startTime") Long startTime,
            @RequestParam("endTime")Long endTime,
            @RequestParam("iotId")String iotId) {
        List<DeviceDataVO> list = iIDeviceService.queryDeviceDataByWeek(functionId,startTime,endTime,iotId);
        return R.ok(list);
    }
    @GetMapping("/pageQueryAlertData")
    @ApiOperation("分页查询预警数据")
    public void method(){

    }
}
